@REM 编译之前获取版本信息和编译信息,赋值之间不能使用空格

@echo off
setlocal enabledelayedexpansion

cd ..
@REM 获取当前系统时间
set cur_date=%date:~0,10%
set cur_date=%cur_date:/=%
set cur_time=%time:~0,10%
set cur_time=%cur_time::=%
set cur_time=%cur_time:.=%
set cur_Compile_date=%cur_date:~0,4%-%cur_date:~4,2%-%cur_date:~6,2%
set cur_Compile_time=%cur_time:~0,2%-%cur_time:~2,2%-%cur_time:~4,2%
@REM echo "cur_date_time = %cur_date%%cur_time%"

@REM 获取git id信息
if exist git_msg.ini del git_msg.ini
git rev-parse HEAD>>git_msg.ini
set /p git_commit_id=<git_msg.ini
del git_msg.ini
@REM echo "git commit id = !git_commit_id!"

@REM 获取git时间
(git log --pretty=format:%%aN -1)>>git_msg.ini
set /p git_user=<git_msg.ini
del git_msg.ini
@REM echo "git user = %git_user%"

@REM 获取git提交时间
(git log --pretty=format:%%aD -1)>>git_msg.ini
set /p git_time=<git_msg.ini
del git_msg.ini
@REM echo "git commit time = %git_time%"

@REM 将获取的数据保存到version.h文件中
rem
cd .\user
if exist versioninfo.h del versioninfo.h

set GIT_USER_HEADER=#define GIT_USER  
set GIT_COMMIT_ID_HEADER=#define GIT_COMMIT_ID
set GIT_COMMIT_TIME_HEADER=#define GIT_COMMIT_TIME
set COMPILE_TIME_HEADER=#define COMPILE_TIME

echo !GIT_USER_HEADER!          "!git_user!">>versioninfo.h
echo !GIT_COMMIT_ID_HEADER!     "!git_commit_id!">>versioninfo.h
echo !GIT_COMMIT_TIME_HEADER!   "!git_time!">>versioninfo.h
echo !COMPILE_TIME_HEADER!      "!cur_Compile_date!-!cur_Compile_time!">>versioninfo.h